<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var
include_once(dirname(__FILE__) . "/../tools/smarty/libs/Smarty.class.php");					//--> out template

require_once(dirname(__FILE__) . "/../controlHeader.php");					//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->

include_once("impl/ContentGroupImpl.php");
include_once("impl/CategoryImpl.php");
include_once("impl/TagImpl.php");


	
$contGimpl	= new ContentGroupImpl(DB_TAG_MM);
$oCatImpl 	= new CategoryImpl(DB_TAG_MM);
$tagImpl	= new TagImpl(DB_TAG_MM);


$error_message 	= '';

$name		= '';
$status		= '1';
$recommend	= '0';



if(isset($_POST['Submit'])){
	$name			= trim($_POST['name']);
	$tags			= trim($_POST['tags']);
	
	$description	= trim($_POST['description']);
	
	$recommend		= $_POST['recommend'];
	$status			= $_POST['status'];
	
	$catIds			= $_POST['catIds'];// array
	
	$dto = new ContentGroupDto();
				
	$dto->name 			= $name;
	$dto->comments 		= $comments;
	$dto->description	= $description;
	$dto->status		= $status;
	$dto->recommend		= $recommend;
	
	$dto->r_popular		= 0;
	
	$id = $contGimpl->add($dto);
	if($id){
		$contGimpl->addCategories($id, $catIds);
		
		$tagIds = $tagImpl->addTags($tags);
		foreach($tagIds as $tagId)
			$contGimpl->addTag($id, $tagId);
		
	}
}

$catLeaf 		= $oCatImpl->getLeafList();

$arrStatus 		= array('1' => 'Online', '0' => 'Offline');
$arrRecommend 	= array('1' => 'Yes', '0' => 'No');


/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrStatus', $arrStatus);
$smarty->assign('status', $status);

$smarty->assign('arrRecommend', $arrRecommend);
$smarty->assign('recommend', $recommend);

$smarty->assign('tags', $tags);
$smarty->assign('name', $name);

$smarty->assign('description', $description);

$smarty->assign('catLeaf', $catLeaf);
$smarty->assign('catIds', $catIds);


$smarty->display('listContentGroup_Add.htm');
?>
